package com.hengpeng.msls.vo.message;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hengpeng.msls.controller.BaseController;
import com.hengpeng.msls.util.WeixinUtil;
import com.hengpeng.msls.vo.message.Menu;

/**
 * 菜单管理器类 
 * @author ChenXiaobao
 * @date 2014-3-18 下午04:15:58
 */
@Controller
@RequestMapping("/create")
public class MenuManager extends BaseController{
		private static Logger log = LoggerFactory.getLogger(MenuManager.class);  
		/**
		* <pre>
		* 创建微信菜单
		* </pre>
		* @param     
		* @return void
		 */
		@RequestMapping(value = "/createMenu")
	    public String createMenu(HttpServletRequest request) {  
			String basePath=  getBasePath(request);
	        // 调用接口获取access_token  
	        String at = WeixinUtil.getmAccessToken();  
	        
	        if (null != at) {  
	            // 调用接口创建菜单  
	            int result = WeixinUtil.createMenu(getMenu(basePath), at);  
	  
	            // 判断菜单创建结果  
	            if (0 == result){  
	                log.info("菜单创建成功！");  
	            }else{  
	                log.info("菜单创建失败，错误码：" + result); 
	            } 
	        }else{
	        	return "/404.html";
	        }  
	        
	        return "/test.jsp";
	    }  
	    
	    
	  
	    /** 
	     * 组装菜单数据 
	     *  
	     * @return 
	     */  
	    private static Menu getMenu(String basePath) {  
	    	ViewButton btn11 = new ViewButton();  
	        btn11.setName("定投查询");  
	        btn11.setType("view");  
	        btn11.setUrl(basePath+"/page/fucaidtou/login.jsp?type=1001"); 
	  
	        CommonButton btn12 = new CommonButton();  
	        btn12.setName("开奖公告");  
	        btn12.setType("click");  
	        btn12.setKey("12");  
	  
	        CommonButton btn13 = new CommonButton();  
	        btn13.setName("资讯促销");  
	        btn13.setType("click");  
	        btn13.setKey("13");  
	  
	  
	        CommonButton btn21 = new CommonButton();  
	        btn21.setName("机选号码");  
	        btn21.setType("click");  
	        btn21.setKey("21");  
	  /*      
	        ViewButton btn21 = new ViewButton();  
	        btn21.setName("机选号码");  
	        btn21.setType("view");  
	        btn21.setUrl(basePath+"/page/fucaidtou/dtssq.jsp");  */
	  
	        ViewButton btn22 = new ViewButton();  
	        btn22.setName("复式分注");  
	        btn22.setType("view");  
	        btn22.setUrl(basePath+"/page/fucaidtou/dtssq.jsp"); 
	        
	        ViewButton btn23 = new ViewButton();  
	        btn23.setName("胆拖分注");  
	        btn23.setType("view");  
	        btn23.setUrl(basePath+"/page/fucaidtou/dantuo.jsp"); 
	    /*    
	        CommonButton btn23 = new CommonButton();  
	        btn23.setName("胆拖分注");  
	        btn23.setType("click");  
	        btn23.setKey("23");  */
	  
	  
	        CommonButton btn31 = new CommonButton();  
	        btn31.setName("五重服务");  
	        btn31.setType("click");  
	        btn31.setKey("31");  
	  
	        
	        CommonButton btn32 = new CommonButton();  
	        btn32.setName("如何办理");  
	        btn32.setType("click");  
	        btn32.setKey("32");  
	  
	        CommonButton btn33 = new CommonButton();  
	        btn33.setName("银行网点");  
	        btn33.setType("click");  
	        btn33.setKey("33");  
	  
	        ComplexButton mainBtn1 = new ComplexButton();  
	        mainBtn1.setName("我的定投");  
	        mainBtn1.setSub_button(new Button[] { btn11, btn12, btn13});  
	  
	        ComplexButton mainBtn2 = new ComplexButton();  
	        mainBtn2.setName("快速选号");  
	        mainBtn2.setSub_button(new Button[] { btn21, btn22, btn23 });  
	  
	        ComplexButton mainBtn3 = new ComplexButton();  
	        mainBtn3.setName("认识定投");  
	        mainBtn3.setSub_button( new Button[]  { btn31, btn32, btn33 });  
	  
	        /** 
	         * 这是公众号目前的菜单结构，每个一级菜单都有二级菜单项
	         *  
	         */  
	        Menu menu = new Menu();  
	        menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });  
	  
	        return menu;  
	    }  
	}  

